﻿<?php
    setlocale(LC_TIME, "es_ES");
    include('php/includes/definer.php');
?>
<!DOCTYPE html>
<head>
    <?php
        include('php/printers/head.printer.php');
        include('common/head.php')
    ?>
</head>
<body>
<main>
    <?php include('common/header.php') ?>
    <div class="main-content category">
        <div class="wrapper">
            <?php include('php/printers/header.printer.php'); ?>

            <aside class="main-aside">
                <div class="recent-posts">
                    <h4>Posts recientes</h4>
                    <div class="thumbs-grid">
                        <?php include(INC.'php/printers/postRecientes.printer.php'); ?>
                    </div>
                </div>
                
                <div class="adv-aside">
                    <div class="content"></div>
                </div>
            </aside>

            <div class="posts">
                <div id="">
                    <?php
                        $cuantos = 6;
                        $size = 'big';
                        include('php/printers/postList.printer.php');
                    ?>
                </div>
            </div>
        </div>
        <nav class="posts-navigation">
            <div class="wrapper">
                <div class="posts-pagination">
                    <?php echo(Paginador::printNumbers($cuantos, $total, $pagina)); ?>
                </div>
                <?php include('php/printers/selectMes.printer.php'); ?>
            </div>
        </nav>
    </div>
    <?php include('common/footer.php') ?>
</main>

<?php include('common/scripts.php') ?>
<script type="text/javascript" src="js/jquery.slides.min.js"></script>
<script type="text/javascript" src="js/masonry.min.js"></script>
<script type="text/javascript" src="js/plugin/jquery-timeago/jquery-timeago.min.js"></script>
<script type="text/javascript" src="js/plugin/jquery-timeago/jquery-timeago-es.min.js"></script>
<script type="text/javascript" src="js/lurocks.min.js"></script>
<script>
    
    var CATEGORIA = <?php echo($jsCategoria); ?>;
    var POST = <?php echo($jsPost); ?>;
    $('.select').removeClass('no-js');
    $(document).on('change', 'select', function() {
        var selected = $('option:selected', this).text();
        $(this).siblings('.current').text(selected);
        window.location = $(this).val().replace(/([a-z]+) ([0-9]{4})/, '$2/$1');
    });
    
    //reload publiciadad
    function reloadPublicidad () {
        $('.adv-aside .content').html('');
        var  banner;
        publicidad.getMediums(CATEGORIA, POST, function () {
            while (banner = publicidad.showMedium()) {
                $('.adv-aside .content').append(banner);
            }
        });
        publicidad.getLarges(CATEGORIA, POST, function () {
            for (var i=0; i<$('div.big').length; i++) {
                if (banner = publicidad.showLarge()) {
                    $('.posts .post').eq(i).after(banner.wrap('<div class="adv-category"></div>').closest('.adv-category'));
                }
            }
        });
    }
    //timeago
    $('.timeago').timeago();
        //paginar
        $('.posts-pagination a').click(function (event) {
            event.preventDefault();
            var pagina = location.href.match(/\/([0-9]+)$/);
            if (!pagina || pagina[1] != $(this).attr('data-pagina')) location.href = location.href.replace(/\/([0-9]+)$/, '')+'/'+$(this).attr('data-pagina')
        })
        //publicidad
        reloadPublicidad();
        //setInterval(reloadPublicidad, 1000*60*2);
</script>
</body>
</html>